﻿using UnityEngine;
using System.Collections;

public class EnemySpawner : MonoBehaviour
{
	public GameObject spawnPointContainer;
	public EnemyRoomController enemyController;

	private Transform[] spawnPoints;
	private bool alreadySpawned;

	void Awake()
	{
		if(spawnPointContainer)
		{
			spawnPoints = spawnPointContainer.GetComponentsInChildren<Transform>();
		}
		alreadySpawned = false;
	}


	void OnTriggerEnter(Collider other)
	{
		if(!alreadySpawned)
		{
			if(spawnPointContainer)
			{
				for(int i = 1 ; i < spawnPoints.Length; ++i) // starts from 1 because the first one is Vector3.zero
				{
					spawnPoints[i].GetComponent<SpawnRateController>().SetActive(true);
					enemyController.IncreaseEnemyCount();
				}
				alreadySpawned = true;
			}
		}
	}
}